<?php
namespace Home\Controller;
class IndexController extends PublicController
{
    public function Index(){
        $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
        preg_match("#http://(.*?)\.#i ",$url,$match);
        if($match[1]==www){
            $cityOb = M("City");
            $Ip = new \Org\Net\IpLocation('qqwry.dat');
            $ip = get_client_ip();
            $arr = $Ip->getlocation($ip);
            $country = $arr["country"];
            $city = iconv("GB2312","UTF-8",$country);
            $arr = explode(省,$city);
            $data=$arr["1"];
            $city_id=$cityOb ->getByName( $data,'id');
        }else{
            $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
            preg_match("#http://(.*?)\.#i ",$url,$match);
            $cityOb = M("City");
            $arr = $cityOb->where("pinyin='$match[1]'")->find();
            $data = $arr['name'];
        }
       $comOb = M("Gongsi");
        $arrr = $comOb->where("isshow=1 and s_city='$data'")->select();
        $this->assign('arrr',$arrr);
        $this->assign('city_id',$city_id);
        $this->getip();
        $this->news();
        $this->biao();
        $this->gongdi();
        $this->baike();
        $this->fengshui();
        $this->xuancai();
        $this->qiandan();
        $this->display();
    }
    function news(){
      $newOb = M("Baikelist");
      $arr1 = $newOb->where("bid=13")->limit(5)->select();
      $this->assign('arr1',$arr1);
    }
    function gongdi(){
      $gongdiOb = M("Gongdi");
      $gongdi = $gongdiOb->select();
      $this->assign('gongdi',$gongdi);
    }
    function biao(){
      $biaoOb = M("Biao");
        $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
        preg_match("#http://(.*?)\.#i ",$url,$match);
        if($match[1]==www){
            $Ip = new \Org\Net\IpLocation('qqwry.dat');
            $ip = get_client_ip();
            $arr = $Ip->getlocation($ip);
            $country = $arr["country"];
            $city = iconv("GB2312","UTF-8",$country);
            $arr = explode(省,$city);
            $data=$arr["1"];
        }else{
            $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
            preg_match("#http://(.*?)\.#i ",$url,$match);
            $cityOb = M("City");
            $arr = $cityOb->where("pinyin='$match[1]'")->find();
            $data = $arr['name'];
        }
//      $biao = $biaoOb->where("shstatus=1 and s_city='$data'")->select();
        $biao = $biaoOb->where("shstatus=1")->order('id desc')->select();
      $this->assign('biao',$biao);
    }
    function baike(){
        $bkOb = M("Baikelist");
        $arr2 = $bkOb->limit(5)->select();
        $this->assign('arr2',$arr2);
    }
    function fengshui(){
        $fengshuiOb = M("Baikelist");
        $arr3 = $fengshuiOb->where("bid=17")->limit(5)->select();
        $this->assign('arr3',$arr3);
    }
    function xuancai(){
        $xuancaiOb = M("Baikelist");
        $arr4 = $xuancaiOb->where("bid=5")->limit(5)->select();
        $this->assign('arr4',$arr4);
    }
//    function baojia(){
//        $bjadd = M("Baojia");
//        $_POST["addtime"]=time();
//        $_POST["ip"]=get_client_ip();
//        $re = $bjadd->data($_POST)->add();
//        if($re){
//            echo json_encode(array('msg'=>1));
//        }
//    }
    function xiaoguotu(){
        $xiaoOb = M("Xiaoguotu");
        $_POST["addtime"]=time();
        $_POST["ip"]=get_client_ip();
        $re = $xiaoOb->data($_POST)->add();
        if($re){
            echo json_encode(array('msg'=>1));
        }
    }
    function qiandan(){
        $Ob = M("Qiandan");
        $qiandan = $Ob->select();
        $this->assign('qiandan',$qiandan);
    }
    function layout(){
        $this->layout();
    }
}
